<?php
/**
 * @title 5472. 重新排列字符串 - 新建字符串
 * @author start2004
 */


class Solution {

    /**
     * @param String $s
     * @param Integer[] $indices
     * @return String
     */
    function restoreString($s, $indices) {
        /**
         * @since 2020-07-27 字符串长度
         */
        $len = strlen($s);

        /**
         * @since 2020-07-27 遍历
         */
        $newS = str_repeat(" ", $len);
        for ($i=0; $i<$len; $i++){
            $newS[$indices[$i]] = $s[$i];
        }

        /**
         * @return
         */
        return $newS;
    }
}



/**
 * @url http://127.0.0.1/leetcode/202007/2020.07.26_2.php
 */
$datas = [
    ["codeleet",[4,5,6,7,0,2,1,3]],
    ["abc", [0,1,2]],
    ["aiohn", [3,1,4,2,0]],
    ["aaiougrt", [4,0,2,6,7,3,1,5]],
    ["art", [1,0,2]],
];

include_once dirname(__DIR__) . DIRECTORY_SEPARATOR ."xhprof.php";
$xhprof = new Xhprof();
foreach ($datas as $data){
    var_dump($data);

    $obj = new Solution();
    $result = $obj->restoreString($data[0], $data[1]);
    var_dump($result);
    echo str_repeat("<br>", 3);
}
$xhprof->end();
